using System;
using Dto;
using Model;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class InfoPanel : UIBase
    {
        private Text _textName;
        private Text _txtLv;
        private Slider _sldExp;
        private Text _txtExp;
        private Text _txtBeen;


        private void Awake()
        {
            Bind(UIEvent.REFRESH_INFO_PANEL);
        }

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case UIEvent.REFRESH_INFO_PANEL:
                    // TODO
                    Account account = Models.GameModel.Account;
                    RefreshView(account.nickName,account.lv,account.exp,account.been);
                    break;
            }
        }
        
        private void Start()
        {
            _textName = transform.Find("TextName").GetComponent<Text>();
            _txtLv = transform.Find("TextLv").GetComponent<Text>();
            _sldExp = transform.Find("SliderExp").GetComponent<Slider>();
            _txtExp = transform.Find("TextExp_L").GetComponent<Text>();
            _txtBeen = transform.Find("TextBeen").GetComponent<Text>();
        }

        /**
         * 刷新视图
         * 有参数,包括 名字 等级 经验 豆子
         */
        private void RefreshView(string name, int lv, int exp, int been)
        {
            _textName.text = name;
            _txtLv.text = "Lv." + lv;
            // 等级和经验之间的公式
            int maxExp = lv * 100;
            _txtExp.text = exp + "/" + maxExp;
            _sldExp.value = (float) exp / maxExp;
            _txtBeen.text =  "X " + been;
        }
    }
}